/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package windowComponents;

import data.contact.Contact;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import org.apache.commons.lang3.StringUtils;

/**
 *
 * @author Arcanis
 */
public class ContactListCellRenderer implements ListCellRenderer {

    protected static Border noFocusBorder = new EmptyBorder(15, 1, 1, 1);
    protected static TitledBorder focusBorder = new TitledBorder(LineBorder.createGrayLineBorder(), "title");
    protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        String strValue = "";
        if(value instanceof Contact){
            Contact cont = (Contact)value;
            if(StringUtils.isEmpty(cont.getName()) && StringUtils.isEmpty(cont.getSurname())){
                strValue = cont.getAddress().getAddress();
            }else{
                strValue = cont.getName()+" "+cont.getSurname();
            }            
            cont.getAddress().getAddress();
        }
        return defaultRenderer.getListCellRendererComponent(list, strValue.trim(), index, isSelected, cellHasFocus);
    }
}
